package cn.pxs.dao;

import cn.pxs.entity.Comment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class CommentDao {
    @Autowired
    MongoTemplate mt;

    public void add(Comment comment){
        mt.save(comment);
    }

    public void delById(String id){
        mt.findAndRemove(new Query(Criteria.where("id").is(id)),Comment.class);
    }

    public List<Comment> findAll(){
        List<Comment> lst = mt.findAll(Comment.class);
        return lst;
    }

    public List<Comment> findByUid(String uid){
        List<Comment> lst = mt.find(new Query(Criteria.where("uid").is(uid)), Comment.class);
        return lst;
    }

    public Comment findById(String id){
        Comment c = mt.findById(id, Comment.class);
        return c;
    }




}
